package Model;
import java.io.Serializable;
import java.util.Random;

/**
 * @author Waseem
 * @version 1.0
 */
public class Fighter implements Serializable{
    /**
     * 
     */
    private String name;

    /**
     * 
     */
    private final int attack;

    /**
     * 
     */
    private final int defense;

    /**
     * 
     */
    private final int luck;
   
    /**
     * 
     */
    private int health;
   
    /**
     * 
     */
    private final Random rand;
    
    
    /**
     * @param attack Attack power of fighter
     * @param defense Defense of fighter
     * @param health Health of fighter
     */
    public Fighter(int attack, int defense, int health){
        this.attack = attack;
        this.defense = defense;
        this.health = health;
        luck = attack >> 1;
        rand = new Random();
    }
       
    /**
     * Getter for the variable health
     * 
     * @return health
     */
    public int getHealth(){
    	return health;
    	}
    
    /**
     * Decreases health based on damage
     * 
     * @param damage Damage that the player will take
     */
    public void takeDamage(int damage){
        final int diff = Math.max(damage - defense, 0);
        health = health - diff;
        //System.out.println(name + " avoided " + ((diff == 0) ? damage:defense) + "!");
    }
    
    /**
     * Assigns attack damage with inflations
     * 
     * @attack changed attack power
     */
    public int fastAttack(){
        final int attack = this.attack - (luck >> 1) + rand.nextInt(luck + 1);
        //System.out.print(name + " used a fast attack for " + attack + " damage! ");
        return attack;
    }
    
    /**
     * Assigns attack damage 
     * 
     * @return attack power
     */
    public int strongAttack(){
        System.out.print(name + " used a strong attack for " + attack + " damage! ");
        return attack;
    }
    
    /**
     * temporarily inflates defense
     * 
     * @return inflated defense
     */
    public int getDefense(){
        return defense + rand.nextInt((luck >> 1) + 1);
    }
    
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		return super.toString();
	}
    
}